﻿using System.Collections.Generic;
using System.Linq;
using SportsStore.Model;
using SportsStore.Web.Models.Helper;

namespace SportsStore.Web.Models.Product
{
  public class ProductsViewModel
  {
    private List<ProductViewModel> _products = new List<ProductViewModel>();

    public PagingInfoViewModel PagingInfo { get; set; }

    public ProductsViewModel()
    { 
    }

    public List<ProductViewModel> Products
    {
      get { return _products; }
      set { _products = value; }
    }

    public string CurrentCategory { get; private set; }

    public void AddProducts(PagedResult<SportsStore.Model.Product> products)
    {
      foreach (SportsStore.Model.Product product in products.Results)
      {
        var pvm = new ProductViewModel(product);
        Products.Add(pvm);
      }

      PagingInfo = new PagingInfoViewModel
      {
        CurrentPage = products.CurrentPage,
        TotalItems = products.TotalItems,
        ItemsPerPage = products.ItemsPerPage,
        TotalPages = products.TotalPages
      };
    }

    public void SetCategory(string category)
    {
      CurrentCategory = category;
    }
  }
}